using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeCompressedClip:Upgrade {

	bool compressed;

	static EventSubscriber<ReloadStartEventArgs> eventSubscriber = new EventSubscriber<ReloadStartEventArgs>();
	static UpgradeCompressedClip() {
		Weapon.ReloadStart+=eventSubscriber.TargetEventHandler;
	}

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		eventSubscriber.SubscribeSingle(weapon.weapon,Weapon_ReloadStart);
	}

	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		eventSubscriber.UnsubscribeSingle(weapon.weapon,Weapon_ReloadStart);
	}

	private void Weapon_ReloadStart(object _sender,ReloadStartEventArgs e) {
		Weapon sender = _sender as Weapon;
		if(sender.currentClip.content.Count>=sender.currentClip.clipSize) {
			compressed=true;
			e.stat.overrideToLoad=true;
		} else compressed=false;
	}

	protected override void ClipSizeDecidingEventHandler(object _sender,ReloadEventArgs e) {
		if(!compressed) return;
		base.ClipSizeDecidingEventHandler(_sender,e);
	}

	protected override void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		if(!compressed) return;
		base.ProjectileFiringEventHandler(_sender,e);
	}

	public override void Update(object sender,WeaponEventArgs e) {
		base.Update(sender,e);
		if(compressed) AddProgression(1);
	}

}
